<?php

namespace app\admin\model;

use think\Model;


class Clients extends Model
{

    

    

    // 表名
    protected $name = 'clients';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text',
        'time_text',
        'status_text',
        'success_status_text',
        'jf_time_text'
    ];
    

    
    public function getSexList()
    {
        return ['1' => __('Sex 1'), '2' => __('Sex 2'), '0' => __('Sex 0')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getSuccessStatusList()
    {
        return ['1' => __('Success_status 1')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['time']) ? $data['time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSuccessStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['success_status']) ? $data['success_status'] : '');
        $list = $this->getSuccessStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJfTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['jf_time']) ? $data['jf_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setJfTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function goods()
    {
        return $this->belongsTo('Goods', 'goods_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function ltder()
    {
        return $this->belongsTo('Ltder', 'pid', 'uid', [], 'LEFT')->setEagerlyType(0);
    }


    public function ltd()
    {
        return $this->belongsTo('Ltd', 'ltd_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
